# Maintainer: Peter Budai <peterbudai@hotmail.com>

_realname=yarn
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.7.0
pkgrel=1
pkgdesc="Fast, reliable, and secure dependency management (mingw-w64)"
arch=('any')
url="http://yarnpkg.com"
license=("BSD")
depends=("${MINGW_PACKAGE_PREFIX}-nodejs")

source=("https://github.com/yarnpkg/${_realname}/releases/download/v$pkgver/${_realname}-v$pkgver.tar.gz")
sha256sums=('e7720ee346b2bd7ec32b7e04517643c38648f5022c7981168321ba1636f2dca3')

package() {
  cd "${srcdir}/${_realname}-v$pkgver"

  install -dm755  "$pkgdir"/${MINGW_PREFIX}/lib/node_modules/yarn
  cp -R * "$pkgdir"/${MINGW_PREFIX}/lib/node_modules/yarn

  install -dm755 "$pkgdir"/${MINGW_PREFIX}/bin
  cp bin/yarn "$pkgdir"/${MINGW_PREFIX}/bin/
  cp bin/yarn.cmd "$pkgdir"/${MINGW_PREFIX}/bin/
  cp bin/yarnpkg "$pkgdir"/${MINGW_PREFIX}/bin/
  cp bin/yarnpkg.cmd "$pkgdir"/${MINGW_PREFIX}/bin/

  # update path to point to the right place
  sed -i "s|$basedir/yarn.js|$basedir/../lib/node_modules/yarn/bin/yarn.js|" "$pkgdir"/${MINGW_PREFIX}/bin/yarn
  sed -i 's|yarn.js|\\..\\lib\\node_modules\\yarn\\bin\\yarn.js|' "$pkgdir"/${MINGW_PREFIX}/bin/yarn.cmd
  sed -i 's|./yarn.js|../lib/node_modules/yarn/bin/yarn.js|' "$pkgdir"/${MINGW_PREFIX}/bin/yarnpkg

  install -Dm644 LICENSE "$pkgdir/${MINGW_PREFIX}/share/licenses/$pkgname/LICENSE"
  install -Dm644 README.md "$pkgdir/${MINGW_PREFIX}/share/doc/$pkgname/README.md"
}


